<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html lang="en">
	<head>
		
		<meta charset="utf-8" />
		<title>菜单</title>
		<meta name="description" content="overview & stats" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link href="<%=contextPath%>/static/css/bootstrap.min.css" rel="stylesheet" />
		<link href="<%=contextPath%>/static/css/bootstrap-responsive.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="<%=contextPath%>/static/css/font-awesome.min.css" />
		<link rel="stylesheet" href="<%=contextPath%>/static/css/ace.min.css" />
		<link rel="stylesheet" href="<%=contextPath%>/static/css/ace-responsive.min.css" />
		<link rel="stylesheet" href="<%=contextPath%>/static/css/ace-skins.min.css" />
		<script type="text/javascript" src="<%=contextPath%>/static/js/jquery-1.7.2.js"></script>	
		<!-- ajax表单提交-->
		<script src="<%=contextPath%>/js/jquery.form.js"></script>
		<!--提示框-->
		<script type="text/javascript" src="<%=contextPath%>/static/js/jquery.tips.js"></script>
		
		<script type="text/javascript">
			$(top.hangge());	
			$(document).ready(function(){
				var pid = ${resource.parentId};
				if(pid==0){
					$("#parentId").attr("disabled","disabled");
					$("#menuUrl").attr("readonly","readonly");
				}else{
					$("#form-field-radio1").attr("disabled","disabled");
					$("#form-field-radio2").attr("disabled","disabled");
				}	
			});
				
			function setMUR(value){
				if(value==0){
					$("#menuUrl").val("");
					$("#menuUrl").attr("readonly","readonly");
					$("#form-field-radio1").removeAttr("disabled");
					$("#form-field-radio2").removeAttr("disabled");
				}else{
					$("#form-field-radio1").attr("disabled","disabled");
					$("#form-field-radio2").attr("disabled","disabled");
				}
			}
				//保存
				function save(){
					if($("#menuName").val()==""){
						
						$("#menuName").tips({
							side:3,
				            msg:'请输入菜单名称',
				            bg:'#AE81FF',
				            time:2
				        });
						
						$("#menuName").focus();
						return false;
					}
					if($("#menuUrl").val()==""){
						$("#menuUrl").val('#');
					}
					if($("#menuOrder").val()==""){
						
						$("#menuOrder").tips({
							side:1,
				            msg:'请输入菜单序号',
				            bg:'#AE81FF',
				            time:2
				        });
						
						$("#menuOrder").focus();
						return false;
					}
					
					if(isNaN(Number($("#menuOrder").val()))){
						
						$("#menuOrder").tips({
							side:1,
				            msg:'请输入菜单序号',
				            bg:'#AE81FF',
				            time:2
				        });
						
						$("#menuOrder").focus();
						$("#menuOrder").val(1);
						return false;
					}
					$("#parentId").removeAttr("disabled");
					$("#zhongxin").hide();
					$("#zhongxin2").show();
					$("#menuForm").ajaxSubmit({
			        	url:'<%=contextPath%>/menu/Edit',
			        	type:'post',
			        	dataType:"json",
			        	success:function(data){
			        		if(data.code==200){
			        			top.Dialog.close();
			        		}else{
			        			alert("错误");
			        			$("#zhongxin").show();
			        			$("#zhongxin2").hide();
			        		}
			        	}
			      }); 
				}
				
				function setType(value){
					$("#MENU_TYPE").val(value);
				}
		</script>
		
	</head>
	
	<body>
		<form action="menu/edit.do" name="menuForm" id="menuForm" method="post">
			<input type="hidden" name="id" id="menuId" value="${resource.id}"/>
			<input type="hidden" name="type" id="type" value="${resource.type}"/>
			<input type="hidden" name="state" id="state" value="${resource.state}"/>
			<input type="hidden" name="display" id="MENU_TYPE" value="${resource.display }"/>
			<div id="zhongxin">
			<table>
				<tr>
					<td>
						<select name="parentId" id="parentId" onchange="setMUR(this.value)" title="菜单" >
							<option value="0">顶级菜单</option>
							<c:forEach items="${menuList}" var="menu">
								<option value="${menu.id }" <c:if test="${resource.parentId ==menu.id }">selected</c:if> >${menu.name }</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				
				<tr>
					<td><input type="text" name="name" id="menuName" placeholder="这里输入菜单名称" value="${resource.name }" title="名称"/></td>
				</tr>
				<tr>
					<td><input type="text" name="href" id="menuUrl" placeholder="这里输入链接地址" value="${resource.href }" title="地址"/></td>
				</tr>
				<tr>
					<td><input type="number" name="sort" id="menuOrder" placeholder="这里输入序号" value="${resource.sort}" title="序号"/></td>
				</tr>
				<tr>
					<td style="text-align: center;">
						<label style="float:left;padding-left: 32px;"><input name="form-field-radio" id="form-field-radio1" onclick="setType('1');" <c:if test="${resource.display == '1' }">checked="checked"</c:if> type="radio" value="icon-edit"><span class="lbl">系统菜单</span></label>
						<label style="float:left;padding-left: 5px;"><input name="form-field-radio" id="form-field-radio2" onclick="setType('2');" <c:if test="${resource.display != '1' }">checked="checked"</c:if> type="radio" value="icon-edit"><span class="lbl">业务菜单</span></label>
					</td>
				</tr>
				<tr>
				<td style="text-align: center; padding-top: 10px;">
					<a class="btn btn-mini btn-primary" onclick="save();">保存</a>
					<a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
				</td>
			</tr>
			</table>
			</div>
			<div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><img src="<%=contextPath%>/static/images/jiazai.gif" /><br/><h4 class="lighter block green"></h4></div>
		</form>
	</body>
</html>